package com.mjt.admin.controller;


import com.mjt.admin.model.RespBean;
import com.mjt.admin.model.RespDataBean;
import com.mjt.admin.pojo.Supplier;
import com.mjt.admin.query.SupplierQuery;
import com.mjt.admin.service.ISupplierService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * <p>
 * 供应商表 前端控制器
 * </p>
 *
 * @author 莫某人
 * @since 2021-11-01
 */
@Controller
@RequestMapping("/supplier")
public class SupplierController {

    @Resource
    private ISupplierService supplierService;

    /**
     * @description 打开供应商管理页面
     * @author 莫某人
     * @date 15:04 2021/11/1
     * @param
     * @return {@link }
     **/
    @RequestMapping("index")
    public String index(){
        return "/supplier/supplier";
    }



    /**
     * @description 打开添加|修改供应商页面
     * @author 莫某人
     * @date 15:04 2021/11/1
     * @param
     * @return {@link }
     **/
    @RequestMapping("addOrUpdateSupplierPage")
    public String addOrUpdateSupplierDialog(Integer id, Model model){


        if (id!=null){
            //修改页面
            Supplier supplier = supplierService.getById(id);
            model.addAttribute("supplier",supplier);
            return "/supplier/add_update";
        }else {
            //添加页面
            return "/supplier/add_update";
        }


    }







    /**
     * @description 查询供应商列表
     * @author 莫某人
     * @date 15:10 2021/11/1
     * @return {@link }
     **/
    @RequestMapping("list")
    @ResponseBody
    public RespDataBean<Supplier> supplierList(SupplierQuery supplierQuery){

        return supplierService.supplierList(supplierQuery);

    }

    /**
     * @description 供应商添加
     * @author 莫某人
     * @date 15:35 2021/11/1
 * @param
     * @return {@link }
     **/
    @RequestMapping("/save")
    @ResponseBody
    public RespBean saveSupplier(Supplier supplier){
        supplierService.saveSupplier(supplier);
        return RespBean.success("添加供应商成功！");
    }


    /**
     * @description 更新供应商信息
     * @author 莫某人
     * @date 15:52 2021/11/1
 * @param supplier
     * @return {@link RespBean}
     **/
    @RequestMapping("/update")
    @ResponseBody
    public RespBean updateSupplier(Supplier supplier){

        supplierService.updateSupplier(supplier);


        return RespBean.success("修改供应商信息成功！");

    }
    /**
     * @description 删除供应商
     * @author 莫某人
     * @date 16:07 2021/11/1
     * @param ids
     * @return {@link RespBean}
     **/

    @RequestMapping("delete")
    @ResponseBody
    public RespBean deleteSupplier(Integer[] ids){

        supplierService.deleteSupplier(ids);

        return RespBean.success("删除供应商信息成功！");
    }




}
